package com.bw.services.viewmodel

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import androidx.lifecycle.viewModelScope
import com.bw.lib_base.base.BaseViewModel
import com.bw.services.entity.JmEntityItem
import com.bw.services.model.AddCarRepo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class AddcarViewModel @Inject constructor(val addCarRepo: AddCarRepo):BaseViewModel(){

    private val _addNameServiceData= MutableStateFlow<List<JmEntityItem>?>(null)
    val addNameServiceData: MutableStateFlow<List<JmEntityItem>?> = _addNameServiceData

    fun getVehicleName(){
        viewModelScope.launch {
            if(isInitLife()){
                lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED,{
                    val data=addCarRepo.getCarName()
                    Log.i("===","aa${data}")
                    _addNameServiceData.emit(data)
                })
            }
        }
    }

}